﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;


public class LiteAnimationManagerWnd : EditorWindow
{
    private GameObject tempObj;
    [MenuItem("Tools/LiteAnim/LiteAnimManager")]
    public static void ShowWnd()
    {
        GetWindow<LiteAnimationManagerWnd>();
    }

    private void OnGUI()
    {
    
        var rect = new Rect(10, 30, position.width - 20, position.height - 20);
        var temp = DragAreaGetObject.GetOjbect();
        if (temp != null)
        {
            Debug.Log(temp);
            string dragPath = AssetDatabase.GetAssetPath(temp);
            if(dragPath!="")
                FavoritesCtl.Inst.Add(dragPath);
        }
        
        
        GUILayout.Space(5);
        tempObj = EditorGUILayout.ObjectField(tempObj,typeof(GameObject)) as GameObject;
        GUILayout.BeginHorizontal();

        //        foreach (var fi in FavoritesModel.Inst.GetAll())
        //        {
        //            for (int i = 0; i <= 6; i++)
        //            {
        //                GUILayout.Box(fi.GetName(), GUILayout.Width(100), GUILayout.Height(100));
        //            }
        //        }

        var eve = Event.current;
        if (eve.type == EventType.MouseDrag)
        {
              SetupDragAndDrop(eve);
            Debug.LogError("drag....");
        }
        else if (eve.type == EventType.DragPerform)
        {
            Debug.LogError("dragPerform");
        }
        else if (eve.type == EventType.dragUpdated)
        {
            Debug.LogWarning("dragUpdated");
        }
        var items = FavoritesModel.Inst.GetAll();

        // get resulting rectangles of items
        //var style = EditorStyles.miniButton;
        var style = EditorStyles.helpBox;
        var boxes = EditorGUIUtility.GetFlowLayoutedRects(rect, style, 4, 4, FavoritesModel.Inst.GetAllToString());
        for (int i = 0; i < boxes.Count; i++)
        {
            var temprect = boxes[i];
            GUI.Box(temprect,items[i].GetName(),style);
      
        }

        GUILayout.BeginHorizontal();

        if (GUILayout.Button("fff"))
        {
            DragAndDrop.PrepareStartDrag();
            //DragAndDrop.SetGenericData(k_gen);
            DragAndDrop.objectReferences = new UnityEngine.Object[] {tempObj}; 
            DragAndDrop.StartDrag("fffff");
        }

    }

    protected  void SetupDragAndDrop(Event eve) {
        DragAndDrop.PrepareStartDrag();
        //DragAndDrop.SetGenericData(k_gen);
        DragAndDrop.objectReferences = new UnityEngine.Object[] { tempObj };
        DragAndDrop.StartDrag("fffff");
    }
}
